package de.baumann.browser.units;

import android.content.Context;

import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;

public class LocationUnit {
    public static AMapLocationClient mLocationClient;
    public static AMapLocationClientOption mLocationOption;

    public static void initLocation(Context context, AMapLocationListener locationListener) {
        mLocationClient = new AMapLocationClient(context);
        mLocationClient.setLocationListener(locationListener);
        mLocationOption = new AMapLocationClientOption();
        //定位场景 使用 签到
        mLocationOption.setLocationPurpose(AMapLocationClientOption.AMapLocationPurpose.SignIn);
        //定位模式 使用 低功耗
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
        //设置单次定位
        mLocationOption.setOnceLocation(true);
        mLocationOption.setOnceLocationLatest(true);
        //设置返回地址描述
        mLocationOption.setNeedAddress(true);
        //设置允许模拟位置
        mLocationOption.setMockEnable(true);
        //关闭缓存机制
        mLocationOption.setLocationCacheEnable(false);
        mLocationClient.setLocationOption(mLocationOption);
    }

    public static void startLocation() {
        if (null != mLocationClient) {
            mLocationClient.stopLocation();
            mLocationClient.startLocation();
        }
    }

    public static void stopLocation() {
        if (null != mLocationClient) {
            mLocationClient.stopLocation();
        }
    }
}
